package com.flowable.candidate.strategy.user;


import com.common.constant.UserConstants;
import com.common.core.domain.entity.SysUser;
import com.common.utils.SecurityUtils;
import com.common.utils.StrUtils;
import com.flowable.candidate.BpmTaskCandidateStrategy;
import com.flowable.common.enums.BpmTaskCandidateStrategyEnum;
import com.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Set;

/**
 * 角色 {@link BpmTaskCandidateStrategy} 实现类
 *
 * @author kyle
 */
@Component
public class BpmTaskCandidateRoleStrategy implements BpmTaskCandidateStrategy {

//    @Resource
//    private RoleApi roleApi;

    @Autowired
    private ISysRoleService roleService;
//    @Resource
//    private PermissionApi permissionApi;

    @Override
    public BpmTaskCandidateStrategyEnum getStrategy() {
        return BpmTaskCandidateStrategyEnum.ROLE;
    }

//    @Override
//    public void validateParam(String param) {
//        Set<Long> roleIds = StrUtils.splitToLongSet(param);
//        roleService.validRoleList(roleIds);
//    }

    @Override
    public Set<Long> calculateUsers(String param) {
        Set<Long> roleIds = StrUtils.splitToLongSet(param);

        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if(sysUser.getDeptId()>0){
            return  roleService.selectUserIdsByRoleIds(roleIds,sysUser.getDeptId());
        }
        return roleService.getUserRoleIdListByRoleIds(roleIds);
    }

}